﻿using MongoDB.Driver;
using Sustainalytics.Entities.RiskRatings;
using System.Collections.Generic;

namespace Sustainalytics.ScreeningTool.Synchronization.Handlers.RiskRatings
{
    public class CoreResearchProfileHandler : ResearchProfileHandler<CoreRiskRatingResearchProfile>, IHandler<CoreRiskRatingResearchProfile>
    {
        public override ProjectionDefinition<CoreRiskRatingResearchProfile> GetProjection(ProjectionDefinitionBuilder<CoreRiskRatingResearchProfile> builder)
            => base.GetProjection(builder)
            .Include(x => x.FinalBetaFactor)
            .Include(x => x.ManageableRiskFactorPercentile)
            .Include(x => x.IndentPercentile);

        public override IEnumerable<ExtraElement> GetExtraElements(CoreRiskRatingResearchProfile entity)
            => EnumerableExtensions.Concat(
                base.GetExtraElements(entity),
                entity.GetExtraElements());
    }

    public static class CoreRiskRatingResearchProfileExtensions
    {
        public static ExtraElementList GetExtraElements(this CoreRiskRatingResearchProfile entity)
            => new ExtraElementList
            {
                { "Overall Beta",                   entity.FinalBetaFactor                },
                { "Overall Manageable Risk Factor", entity.ManageableRiskFactorPercentile },
                { "Constant-Weight-RR",             entity.IndentPercentile               },
            };
    }
}
